<?php
namespace Bshop\Model;
use Think\Model;
class ShopModel extends Model{
	protected $_validate = array(
			array('username','/1[3458]{1}\d{9}$/','商家的账号必须为手机号',0,'regex',1),
			array('username','','帐号名称已经存在！',0,'unique',1), 
			array('password','/^\w{6,}$/','密码必须6个字母以上！',0,'regex',1),
			array('shop_name','require','请输入商家名称'),
			array('class_id','number','请选择商家所属分类'),
			array('provinceid','number','请选择商家所属省份'),
			array('cityid','number','请选择商家所属城市'),
			array('shop_address','require','商家的地址必须'),
			array('east','require','请输入商家的东经'),
			array('north','require','请输入商家的北纬'),
			array('body','require','请输入商家介绍'),
			array('bank','/^[\w\x{4e00}-\x{9fa5}]+$/u','开户银行填写错误',0,'regex',1),
			array('bank_account','require','请输入你的开户账号'),
			array('bank_people','require','请输入你的开户人'),
			array('username,type,id_card,bank,id_card_photo,business_license_photo,business_license','Ckshop','认证信息填写错误',1,'callback',3),
			array('id_card','CKcard','省份证号码填写错误',1,'callback',3),
			array('finance_phone','CKphone','财务联系电话填写错误',1,'callback',3),
	);
   protected function Ckshop($data){
   	   if(!empty($data['username'])){
   	   	    return true  ;
   	   }else{
	   	   	if($data['type']==2 || $data['type']==1){
	   	   		if($data['type'] == 2){
	   	   			if(!empty($data['id_card']) && !empty($data['id_card_photo'])){
	   	   				return true;
	   	   			}else{
	   	   				return false;
	   	   			}
	   	   		}else{
	   	   			if(!empty($data['business_license_photo']) && !empty($data['business_license'])){
	   	   				return true;
	   	   			}else{
	   	   				return false;
	   	   			}
	   	   		}
	   	   	}else{
	   	   		return false;
	   	   	}
   	   }
   	   
   }
   protected function CKcard($data){
   	   if(empty($data)){
   	   	  return true;
   	   }else{
	   	   if(!preg_match('/^\d{17}(\d|x)$/i',$data) and !preg_match('/^\d{15}$/i',$data))
	   	   {
	   	   		return false;
	   	   }else{
	   	   	   return true;
	   	   }
   	   }
   }
   protected function CKphone($data){
   	  if(empty($data)){
   	    return true;
   	  }else{
   	  	if(!preg_match('/^((\d{3,4}-)*\d{7,8}(-\d{3,4})*|(1[3,4,5,7,8])\d{9})$/',$data)){
   	  		return false;
   	  	}else{
   	  		return true;
   	  	}
   	  }
   }
}